package receivers;

import com.rabbitmq.client.*;

import java.io.IOException;

public class ExchangeReceiver extends Receiver{
    //创建一个临时队列
    String queue = channel.queueDeclare().getQueue();

    public ExchangeReceiver(Connection connection, String queueName, boolean persistence, String exchangeName, String exchangeType, String routingKey) throws IOException {
        super(connection, queueName, persistence, exchangeName, exchangeType, routingKey);
    }

    @Override
    public void receive(Consumer consumer) throws IOException {
        channel.exchangeDeclare(exchangeName,exchangeType);
        channel.queueBind(queue,exchangeName,routingKey);
        //获取消费的消息
        channel.basicConsume(queue,true, consumer);
    }
}
